<template>
	<view class="content">
		<uni-nav-bar title="售后工单" left-icon="back" @clickLeft="back">
		</uni-nav-bar>
		<view class="tab-content">
			<view v-for="item in tabList" :class="activeValue === item.value ? 'active-tab' :''"
				@click="handleClick(item.value)">{{item.name}}</view>
		</view>
		<view class="middle-content">
			<swiper class="swiper" :current="activeValue" :duration="300" v-if="orderList.length">
				<swiper-item>
					<scroll-view scroll-y="true" class="scroll-Y flex flex-col" @scrolltolower="reachBottom">
						<view class="order-item" v-for="(item, index) in orderList">
							<view class="flex justify-between">
								<view>{{item.name}}</view>
								<view @click="goDetaiPage(item)">{{item.status}}></view>
							</view>
							<view class="line"></view>
							<view class="flex margin-bottom-sm">
								<view class="name">订单：</view>
								<view>{{item.orderId}}</view>
							</view>
							<view class="flex margin-bottom-sm">
								<view class="name">类型：</view>
								<view class="margin-right-xl">{{item.deviceType}}</view>
								<view class="name">设备：</view>
								<view>{{item.device}}</view>
							</view>
							<view class="flex margin-bottom-sm">
								<view class="name">地址：</view>
								<view>{{item.address}}</view>
							</view>
							<view class="line"></view>
							<button class="mini-btn" type="primary" plain="true" size="mini">取消工单</button>
						</view>
					</scroll-view>

				</swiper-item>
				<swiper-item>
					<view class="order-item" v-for="(item, index) in orderList">
						<view class="flex justify-between">
							<view>{{item.name}}</view>
							<view>{{item.status}}></view>
						</view>
						<view class="line"></view>
						<view class="flex margin-bottom-sm">
							<view class="name">订单：</view>
							<view>{{item.orderId}}</view>
						</view>
						<view class="flex margin-bottom-sm">
							<view class="name">类型：</view>
							<view class="margin-right-xl">{{item.deviceType}}</view>
							<view class="name">设备：</view>
							<view>{{item.device}}</view>
						</view>
						<view class="flex margin-bottom-sm">
							<view class="name">地址：</view>
							<view>{{item.address}}</view>
						</view>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="order-item" v-for="(item, index) in orderList">
						<view class="flex justify-between">
							<view>{{item.name}}</view>
							<view>{{item.status}}></view>
						</view>
						<view class="line"></view>
						<view class="flex margin-bottom-sm">
							<view class="name">订单：</view>
							<view>{{item.orderId}}</view>
						</view>
						<view class="flex margin-bottom-sm">
							<view class="name">类型：</view>
							<view class="margin-right-xl">{{item.deviceType}}</view>
							<view class="name">设备：</view>
							<view>{{item.device}}</view>
						</view>
						<view class="flex margin-bottom-sm">
							<view class="name">地址：</view>
							<view>{{item.address}}</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
			<view v-else class="empty-content">
				<view style="flex: 1;text-align: center;">
					<image src="/static/images/emtpy.png" class="empty-img">
						<view>暂无数据</view>
				</view>

			</view>
			<view class="action-btn">
				<button @click="addworkOrder" class="login-btn cu-btn block bg-blue lg round">新增工单</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeValue: 0,
				tabList: [{
					name: '进行中',
					value: 0,
				}, {
					name: '已完成',
					value: 1,
				}, {
					name: '全部',
					value: 2,
				}],
				orderQueryParams: {
					pageNum: 1,
					pagesize: 10,
					status: 1,
				},
				orderList: [{
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}, {
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}, {
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}, {
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}, {
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}, {
					name: '测试工单',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}],
			}
		},
		methods: {
			handleClick(data) {
				this.orderQueryParams.status = data
				this.activeValue = data
				this.getorderlist()
			},
			addworkOrder() {
				uni.navigateTo({
					url: `/pages/workOrder/add`,
				})
			},
			getorderlist() {
				this.orderList = [{
					name: '测试工单11',
					status: '待处理',
					orderName: '测试工单',
					orderId: 'WX2024060512120001',
					type: '',
					address: '山西临汾市洪洞县涧桥南路',
					device: '奶茶机',
					deviceType: '设备安装',
				}]
			},
			back() {
				uni.navigateBack();
			},
			reachBottom() {
				console.log('refresherrefresh')
			},
			goDetaiPage(item) {
				uni.navigateTo({
					url: `/pages/workOrder/detail?orderId=${item.orderId}`,
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;

		.tab-content {
			height: 80rpx;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			font-size: 30rpx;
			color: #2E3C53;
			padding: 5rpx 0;
			margin-bottom: 30rpx;

			view {
				width: 180rpx;
				margin: 0 auto;
				height: 65rpx;
				line-height: 65rpx;
				text-align: center;
			}

			.active-tab {
				background-color: #fff;
				color: #3B7EFB;
				border-bottom: 2px solid #3B7EFB;
			}
		}

		.middle-content {
			padding: 0rpx 30rpx 10rpx 30rpx;
			flex: 1;
			display: flex;
			flex-direction: column;

			.swiper {
				padding-bottom: 30rpx;
				flex: 1;
			}

			.empty-content {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				flex: 1;
			}

			.empty-img {
				margin-top: 100rpx;
				margin-bottom: 40rpx;
				width: 300rpx;
				height: 200rpx;
			}

			.scroll-Y {
				height: 100%;
			}

			.order-item {
				background: #FFFFFF;
				box-shadow: 0rpx 12rpx 16rpx 0rpx rgba(59, 126, 251, 0.19);
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 20rpx;
			}

			.line {
				position: relative;
				height: 1px;
				background-color: #e2dfdf;
				margin: 20rpx 0;
			}

			.line::after {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 1px;
				background-color: #e2dfdf;
				transform: scaleY(1);
				transform-origin: 0 0;
			}

			.name {
				font-size: 28rpx;
				color: #9097AA;
			}

			.mini-btn {
				border-color: #B9C2D4;
				color: #404C61;
			}
		}
	}
</style>